package com.wjerp.tplus.server.domain.service.impl;

import com.wjerp.tplus.server.domain.entity.sys.RoleInfo;
import com.wjerp.tplus.server.domain.mapper.RoleInfoMapper;
import com.wjerp.tplus.server.domain.service.RoleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author lishuailei
 */
@Service
public class RoleServiceImpl implements RoleService {

    @Resource
    private RoleInfoMapper roleInfoMapper;

    @Override
    public List<RoleInfo> loadAllRole() {
        return roleInfoMapper.selectAll();
    }

    @Override
    public RoleInfo findRoleInfoByName(String roleName) {
        return roleInfoMapper.selectByName(roleName);
    }

    @Override
    public Boolean saveRoleInfo(RoleInfo roleInfo) {
        roleInfo.setCreatedTime(new Date());
        return roleInfoMapper.insertSelective(roleInfo) > 0;
    }

    @Override
    public Boolean updateRoleInfo(RoleInfo roleInfo) {
        return roleInfoMapper.updateByPrimaryKeySelective(roleInfo) > 0;
    }

    @Override
    public Boolean deleteRoleById(Long roleId) {
        return roleInfoMapper.deleteByPrimaryKey(roleId) > 0;
    }

    @Override
    public RoleInfo findRoleInfoById(Long roleId) {
        return roleInfoMapper.selectByPrimaryKey(roleId);
    }
}
